package com.sphd.emanu.fragment.topuporder;


import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.sphd.emanu.R;
import com.sphd.emanu.adapter.MyViewPagerAdapter;
import com.sphd.emanu.fragment.topupdetail.TopupdetailFragment;
import com.sphd.emanu.interfaces.TopCountCallBack;
import com.sphd.emanu.mvp.MVPBaseFragment;
import com.sphd.emanu.pojo.order.DepositOrderCount;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * @Author Hu
 * @Time 2017/4/18 -- 10:55.
 * @Email 87683202@qq.com
 */
public class TopuporderFragment extends MVPBaseFragment<TopuporderContract.View, TopuporderPresenter> implements TopuporderContract.View, TopCountCallBack {

    @BindView(R.id.tabs)
    TabLayout tabs;
    @BindView(R.id.my_vp)
    ViewPager myVp;
    Unbinder unbinder;
    MyViewPagerAdapter myadapter;
    List<Fragment> fragments;
    String[] titles;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_viewpager_tab;
    }
    @Override
    protected void initView() {
        unbinder = ButterKnife.bind(this, rootView);
        setUserVisibleHint(true);
    }

    @Override
    protected void initData() {
        fragments = new ArrayList<>();
        titles = new String[]{"未接收\n0", "未入账\n0", "已入账\n0", "已忽略\n0"};
        for (int i = 0; i < 4; i++) {
            TopupdetailFragment topupdetailFragment = new TopupdetailFragment();
            topupdetailFragment.setType(i);
            topupdetailFragment.setTopCountCallBack(this);
            topupdetailFragment.setArguments(getArguments());
            fragments.add(topupdetailFragment);
        }
        myadapter = new MyViewPagerAdapter(context,getChildFragmentManager(), fragments, titles);
        myVp.setAdapter(myadapter);
        tabs.setupWithViewPager(myVp);
    }

    @Override
    public void callBackTopCount(DepositOrderCount depositOrderCount) {
        titles[0]="未接收\n"+depositOrderCount.getStateCount0();
        titles[1]="未入账\n"+depositOrderCount.getStateCount1();
        titles[2]="已入账\n"+depositOrderCount.getStateCount2();
        titles[2]="已忽略\n"+depositOrderCount.getStateCount2();
        myadapter.notifyDataSetChanged();
    }
}
